using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FPCharacterControllerMovement : MonoBehaviour
{
    private CharacterController characterController;

    private Transform characterTransform;

    public float MovementSpeed = 6.0f;

    public float Gravity = 9.8f;

    private Vector3 MovementDirection;

    private Vector3 updawardVector;

    public float JumpHeight = 2.0f;

    public float CrouchHeight = 1f;

    private float OriginHeight;
    void Start()
    {
        //Application.targetFrameRate = 60;

        characterController = GetComponent<CharacterController>();
        characterTransform = transform;
        OriginHeight = characterController.height;
    }

    // Update is called once per frame
    void Update()
    {
        if(characterController.isGrounded)
        {
            float m_Horizontal = Input.GetAxis("Horizontal");
            float m_Vertical = Input.GetAxis("Vertical");

            MovementDirection = characterTransform.TransformDirection(new Vector3(m_Horizontal, 0, m_Vertical));
            MovementDirection *= MovementSpeed;

            if (Input.GetButtonDown("Jump"))
            {
                updawardVector.y = JumpHeight;
            }
        }
        else
        {
            updawardVector.y -= Gravity * Time.deltaTime;
        }

        characterController.Move((MovementDirection + updawardVector) * Time.deltaTime);
    }

/*    private IEnumerator DoCroudh()
    {

    }*/
}
